package com.bdb.myswipemultitype.activity;

import android.view.View;

import com.bdb.myswipemultitype.bean.ItemBean;
import com.bdb.myswipemultitype.bean.ItemProvider;
import com.xiaoq.base.ui.fragment.LoadMoreFragment;

import java.util.ArrayList;
import java.util.List;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by zinc on 2017/7/26.
 */

public class SwipeMoreFragment extends LoadMoreFragment<ItemBean> {

    public static SwipeMoreFragment newInstance() {
        return new SwipeMoreFragment();
    }

    @Override
    protected void initView(View view) {
        super.initView(view);
        mAdapter.register(ItemBean.class, new ItemProvider());

//        mAdapter.setListener(new SwipeAdapter.SwipeListener() {
//            @Override
//            public void menuClick(View v, int position) {
//
//                Toast.makeText(SwipeMoreFragment.this, "menu:"+v.getId()+";position:"+position, Toast.LENGTH_SHORT).show();
//
//            }
//
//        });

    }

    @Override
    protected Observable<List<ItemBean>> getLoadMoreObservable() {
        return load();
    }

    @Override
    protected void addMoreList(List<ItemBean> list) {
        addList(list);
    }

    private Observable<List<ItemBean>> load(){

        final List<ItemBean> list = new ArrayList<>();
        for (int i = 0; i < 10; ++i) {
            list.add(new ItemBean("tewset"+i));
        }
        return Observable.create(new Observable.OnSubscribe<List<ItemBean>>() {
            @Override
            public void call(Subscriber<? super List<ItemBean>> subscriber) {
                subscriber.onNext(list);
                subscriber.onCompleted();
            }
        });
    }

    @Override
    protected Observable<List<ItemBean>> getInitObservable() {
        return load();
    }
}
